<?php
function ListEmailTemps()
{
global $dbsql,$module,$language,$id;
    $return     = '';

    $sql_select = "select cType,iId from tblconfig where cName like 'EmailTemp%' and cLanguage='$language'";
    $rs         = $dbsql->query($sql_select);
    while($result= $dbsql->fetch_array($rs))
    {
        if($id==0)
        {
            $id = $result['iId'];
        }
        
        $return.= '<div style="padding-left:10px;"';
        if($result['iId']==$id)
		{
			$return.=' class="selected" ';
		}
		$return.='><a href="?module='.$module.'&id='.$result['iId'].'">&raquo;'.$result['cType'].'</a></div>';
    }
    return $return;
}


function LoadConfigEmail($id)
{
global $dbsql,$language;
    ImportClass('json');
	$sql_select="select cType,cName,cValue from tblconfig where iId='$id' and cLanguage='$language'";
	if($result=$dbsql->query_fetch($sql_select))
	{
	  // print_r($result['cValue']);
        $result = FJSON::decode($result['cValue']);
	}
    //echo $result;
	return $result;
}

function InsertConfigEmail($name,$type,$title,$email,$content)
{
    global $dbsql,$language;
    ImportClass('json');
    $arrcode    = array("title"=>$title,"email"=>$email,"content"=>$content);

    $data       = FJSON::encode($arrcode);
    
    $sql_insert = "insert into tblconfig(cName,cType,cValue,cLanguage)
                values('EmailTemp$name','$type','$data','$language')";
	$dbsql->query($sql_insert);
    return $dbsql->insert_id();
}

function UpdateConfigEmail($title,$email,$content)
{
global $dbsql,$id;
    ImportClass('json');
    $arrcode    = array("title"=>$title,"email"=>$email,"content"=>$content);

    $data       = FJSON::encode($arrcode);
    //$data       = mysql_escape_string($data);
    $sql_update = "update tblconfig set
					cValue	= '$data'
				Where iId	= '$id'";
	return $dbsql->query($sql_update);
}
?>